﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;


using System.IO;

namespace Genuilder.Extensibility.Tests
{
	[TestClass]
	public class ExtensibilityTest
	{


		//[TestMethod]
		//public void ShouldLoadPlugin()
		//{
		//    var assemblies = Assembly.LoadFile(@"C:\Users\Nia\Documents\Visual Studio 2008\Projects\Genuilder\Genuilder.Extensibility.TestProject.Gen\bin\Debug\Genuilder.Extensibility.TestProject.Gen.dll");
		//    var dir = @"C:\Users\Nia\Documents\Visual Studio 2008\Projects\Genuilder\Genuilder.Extensibility.TestProject.Gen\bin\Debug\";
		//    AppDomain.CurrentDomain.SetupInformation.PrivateBinPath += ";" + dir;
		//    var t = Activator.CreateInstance(assemblies.GetTypes().First()) as IPlugin;
		//    t.Initialize(null);
		//}


		//public class Toto : MarshalByRefObject
		//{
		//    [Import]
		//    public IPlugin Plugin
		//    {
		//        get;
		//        set;
		//    }

		//    public String Directory
		//    {
		//        get;
		//        set;
		//    }
		//    public String Assembly
		//    {
		//        get;
		//        set;
		//    }

		//    public void Do()
		//    {
		//        AssemblyCatalog catalog = new AssemblyCatalog(Assembly);
		//        CompositionContainer container = new CompositionContainer(catalog);

		//        container.ComposeParts(this);
		//        Assert.IsNotNull(Plugin);
		//        Plugin.Initialize(null);
		//    }
		//}

		//Assembly subDomain_AssemblyResolve(object sender, ResolveEventArgs args)
		//{
		//    return Assembly.Load(args.Name);
		//}

		//[TestMethod]
		//public void ShouldLoadPluginWithMEF()
		//{
		//    var directory = @"C:\Users\Nia\Documents\Visual Studio 2008\Projects\Genuilder\Genuilder.Extensibility.TestProject.Gen\bin\Debug\";
		//    var assembly = Assembly.LoadFile(@"C:\Users\Nia\Documents\Visual Studio 2008\Projects\Genuilder\Genuilder.Extensibility.TestProject.Gen\bin\Debug\Genuilder.Extensibility.TestProject.Gen.dll");
		//    var thisDirectory = Path.GetDirectoryName(
		//                                    GetType().Assembly.Location);
		//    var domain = AppDomain.CreateDomain("hello", null, new AppDomainSetup()
		//    {
		//        ApplicationBase = thisDirectory,
		//        PrivateBinPath = directory + ";" + thisDirectory,
		//    });
		//    AppDomain.CurrentDomain.AssemblyResolve += subDomain_AssemblyResolve;
		//    var t = (Toto)domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(Toto).FullName);
		//    t.Assembly = assembly.Location;
		//    t.Do();
		//}
	}
}
